﻿using System;
using System.Text;

namespace GPS.GPSLanguage
{
    class MagneticVariation
    {
        internal static void ParseLanguage(GPSData gpsData, System.Collections.Queue q)
        {
            String magValToken = (string)q.Dequeue();

            String magDirection = (string)q.Dequeue();

            double val = 0;
            try
            {
                if (magValToken.Length > 0)
                    val = double.Parse(magValToken);
            }
            catch { }

            DirectionType dir = DirectionTypeToken.ParseToken(magDirection);

            gpsData.SetMagneticVariation(val, dir);

            switch (gpsData.MessageType)
            {
                case MessageType.GPRMC:
                    gpsData.SetGPSSentenceComplete();
                    break;
                default:
                    throw new InvalidLanguageException("How did you get here?");
            }
        }
    }
}
